package cn.webwheel.tutorials.plugin;

import cn.webwheel.Filter;
import cn.webwheel.FilterChain;

public class TimerFilter implements Filter {

    private static int idseq;
    private int id;

    public void init() throws Exception {
        id = ++idseq;
    }

    public boolean process(FilterChain chain) throws Exception {
        long t = System.currentTimeMillis();
        try {
            return chain.go();
        } finally {
            t = System.currentTimeMillis() - t;
            String uri = chain.getWebContext().getRequest().getRequestURI();
            System.out.println(uri + " -> " + t + "ms - TimerFilter " + id);
        }
    }

    public void destroy() {
    }
}
